package com.zlt.bkparking.service.impl;


import com.github.pagehelper.PageInfo;
import com.zlt.bkparking.entity.*;
import com.zlt.bkparking.mapper.AppUserMapper;
import com.zlt.bkparking.mapper.BackUserMapper;

import com.zlt.bkparking.mapper.DrivingLicenseMapper;
import com.zlt.bkparking.mapper.LicenseMapper;
import com.zlt.bkparking.service.CheckingService;
import com.zlt.bkparking.utils.CodeUtil.CodeUtil;
import com.zlt.bkparking.vo.AppUserVO;
import com.zlt.bkparking.vo.CheckedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Service
public class CheckingServiceImpl implements CheckingService {

    @Autowired
    private AppUserMapper appUserMapper;

    @Autowired
    private LicenseMapper licenseMapper;

    @Autowired
    private DrivingLicenseMapper drivingLicenseMapper;



    @Override
    public PageInfo<CheckedVO> getInfo(Integer pageNum, Integer pageSize) {

        int totalNum ;

        AppUserExample appUserExample = new AppUserExample();
        List<AppUser> appUsers = appUserMapper.selectByExample(appUserExample);
//        System.out.println("user长度" + appUsers.size());
//        System.out.println("appUsers:"+appUsers);
        totalNum = appUsers.size();
        //使用分页插件
        //PageHelper.startPage(pageNum,pageSize);
        List<CheckedVO> checkedVOS = new ArrayList<>();


        LicenseExample licenseExample = new LicenseExample();
        List<License> licenses = licenseMapper.selectByExample(licenseExample);
//        licenses.forEach(license -> {
//            System.out.println(license.toString());
//        });

        DrivingLicenseExample drivingLicenseExample = new DrivingLicenseExample();

        List<DrivingLicense> drivingLicenses = drivingLicenseMapper.selectByExample(drivingLicenseExample);
        for(int i =0;i<10;i++){
            CheckedVO checkedVO = new CheckedVO();
            //if(licenses.get(i).getAuId() == appUsers.get(i).getAuId()){
            if(licenses.get(i).getlState()==4 || licenses.get(i).getlState()==2){
                checkedVO.setAuId(appUsers.get(i).getAuId());
                checkedVO.setdIPhoto(drivingLicenses.get(i).getDlPhoto());
                checkedVO.setBuId(appUsers.get(i).getAuId());
                checkedVO.setBuNum(drivingLicenses.get(i).getDlId());
                checkedVO.setBuPhoto(appUsers.get(i).getAuPhoto());

            }
            System.out.println(checkedVO.toString());
             checkedVOS.add(i,checkedVO);

            //}

        }

        PageInfo<CheckedVO> pageInfo = new PageInfo<>(checkedVOS);
        System.out.println("pageInfoW:"+pageInfo);
        return pageInfo;
    }

    @Override
    public PageInfo<CheckedVO> UserD() {

//        //阿里云发送短信服务 代码由阿里云短信服务平台生成，拿来用即可 配置相关个人信息
//         //AccessKey ID 账号 AccessKey secret密码
//            DefaultProfile profile = DefaultProfile.getProfile("cn-chengdu", "LTAI5t93Kp2YrKoyzd1iRjJb", "nmvkQ1C7nqt9da2Nf6x2TtrW99aiZE");
//            IAcsClient client = new DefaultAcsClient(profile);
//            //阿里云原有的配置信息我们不需要改动
//            CommonRequest request = new CommonRequest();
//            request.setSysMethod(MethodType.POST);
//            request.setSysDomain("dysmsapi.aliyuncs.com");
//            request.setSysVersion("2017-05-25");
//            request.setSysAction("SendSms");
//
//            //自定义短信信息
//            request.putQueryParameter("PhoneNumbers", "19961712756"); //发送给哪个手机号
//            request.putQueryParameter("SignName", "清峰小栈");  //自己配置的短信签名
//            request.putQueryParameter("TemplateCode", "SMS_254540140"); //自己配置的模板 模版CODE
//
//            //构建一个短信验证码
//            HashMap<String, Object> map = new HashMap<>();
//            map.put("code",8456);
//            request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));   //转换成json字符串
//            try {
//                CommonResponse response = client.getCommonResponse(request); //发送至客户端
//                System.out.println(response.getData());
//            } catch (ClientException e) {
//                e.printStackTrace();
//            }
//        System.out.println(666666);



        CodeUtil.sendEmail("2140489862@qq.com");

        PageInfo<CheckedVO> pageInfo = new PageInfo<>();



        return pageInfo ;
    }

    @Override
    public PageInfo<CheckedVO> UserT(String AuUserName) {


        AppUserExample appUserExample = new AppUserExample();
        appUserExample.createCriteria().andAuUsernameLike("%"+AuUserName+"%");
        List<AppUser> appUsers = appUserMapper.selectByExample(appUserExample);

        PageInfo<CheckedVO> pageInfo = new PageInfo<>();


        return pageInfo ;
    }

    @Override
    public PageInfo<CheckedVO> ResetU() {

        return null;
    }
}
